#include "bottom_setting.h"
#include "ui_bottom_setting.h"
#include "ui_password_input.h"
#include "main.h"


bottom_setting::bottom_setting(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::bottom_setting)
{
    ui->setupUi(this);

}

bottom_setting::~bottom_setting()
{
    delete ui;
}

 void bottom_setting::entrance()
{

         switch(sterilization_protype)
         {
         case BOTTOM_EXHAUST_PROTYPE:  data=&bottom_config;
             ui->label->setText(QString::fromUtf8("下排气程序参数设置"));break;
         case LIQUID_RPOTYPE:  data=&liquid_config;
             ui->label->setText(QString::fromUtf8("液体类程序参数设置"));break;
         case USER_DEFINE_1:  data=&user_define1_config;
             ui->label->setText(QString::fromUtf8("自定义下排1"));break;
         case USER_DEFINE_2:  data=&user_define2_config;
              ui->label->setText(QString::fromUtf8("自定义下排2"));break;
         case USER_DEFINE_3:  data=&user_define3_config;
              ui->label->setText(QString::fromUtf8("自定义下排3"));break;
         default:break;
         }

        temperaturer= data->bottom_exhaust_temperature;
        time= data->bottom_exhaust_time;
        cold_exhaust_times= data->bottom_cold_exhaust_times;
        prebalance_time= data->bottom_prebalance_time;

         ui->temp_lineEdit->setText(QString::number( temperaturer));
         ui->time_lineEdit->setText(QString::number( time));
         ui->cold_exhaust_times_lineEdit->setText(QString::number( cold_exhaust_times));
         ui->prebalance_time_lineEdit->setText(QString::number( prebalance_time));
         ui->cold_exhaust_pressure_lineEdit->setText(QString::number( cold_exhaust_pressure));    
         showFullScreen();
}

 void bottom_setting::getvalue()
 {

        int input=ui->temp_lineEdit->text().toInt();
        if( verify(input, 10,130,"排冷压力应该在10～130 kpa范围内") ) temperaturer=input;

        input=ui->time_lineEdit->text().toInt();
        if( verify(input, 0,9000,"灭菌时间应该为大于零") ) time=input;

        input=ui->cold_exhaust_times_lineEdit->text().toInt();
        if( verify(input, 0,5,"排冷次数应该在0～5 内") ) cold_exhaust_times=input;

        input=ui->prebalance_time_lineEdit->text().toInt();
        if( verify(input, 0,300,"预平衡应该在0～300s内") ) prebalance_time=input;

        input=ui->cold_exhaust_pressure_lineEdit->text().toInt();
        if( verify(input, 10,130,"排冷压力应该在10～130 kpa范围内") )  cold_exhaust_pressure=input;



 }

void bottom_setting::on_buttonBox_accepted()
{
         BUTTON_SOUND;
        getvalue();
        data->bottom_exhaust_temperature=temperaturer;
        data->bottom_exhaust_time=time;
        data->bottom_cold_exhaust_times=cold_exhaust_times;
        data->bottom_prebalance_time= prebalance_time;

      config_changed=true;
      this->close();
      stype->showFullScreen();
}


void bottom_setting::on_buttonBox_rejected()
{     BUTTON_SOUND;
    this->close();
    stype->showFullScreen();
}

bool bottom_setting::verify(int value, int low, int high, const char* tips)
{
    //int value=input.toInt();
    if(value < low || value >high) {
        QMessageBox::warning(this,QString::fromUtf8("输入非法！"), QString::fromUtf8(tips));
        return FALSE;
        }
    else return TRUE;
}


